package com.hk.springsecurity01.utils;

import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author by 何坤
 * @Classname MyWebAuthenticationDetails
 * @Description TODO
 * @Date 2019/11/28 23:05
 */
public class MyWebAuthenticationDetails extends WebAuthenticationDetails {

    private boolean imageCodeIsRight;

    public boolean getImageCodeIsRight(){
        return this.imageCodeIsRight;
    }

    public MyWebAuthenticationDetails(HttpServletRequest request) {
        super(request);
        String imageCode = request.getParameter("captcha");
        HttpSession session = request.getSession();
        String saveImageCode = (String) session.getAttribute("captcha");
        if (!StringUtils.isEmpty(saveImageCode)){
            session.removeAttribute("captcha");
            if (!StringUtils.isEmpty(imageCode) && imageCode.equals(saveImageCode)){
                this.imageCodeIsRight = true;
            }
        }
    }
}
